package com.nidu.demo.log.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.log.convertor.OperateLogConvertor;
import com.nidu.demo.log.convertor.OperateLogCriteriaConvertor;
import com.nidu.demo.log.dto.OperateLogCO;
import com.nidu.demo.log.dto.OperateLogPageQry;
import com.nidu.demo.log.gateway.OperateLogGateway;
import com.nidu.demo.log.model.OperateLog;
import com.nidu.demo.log.model.OperateLogCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 操作日志分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class OperateLogPageQryExe {

    private final OperateLogGateway gateway;
    private final OperateLogConvertor convertor;
    private final OperateLogCriteriaConvertor criteriaConvertor;

    public PageResponse<OperateLogCO> execute(OperateLogPageQry qry) {
        // 1. 转换查询条件
        OperateLogCriteria criteria = criteriaConvertor.toDataObject(qry);

        // 2. 执行分页查询
        PageResponse<OperateLog> page = gateway.pageByCondition(criteria);

        // 3. 转换为DTO并返回
        List<OperateLogCO> operateLogCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(operateLogCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }

}
